/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package media_server;
import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JPanel;

/**
 *
 * @author DELL
 */
public class MediaPanel extends JPanel
{
    public MediaPanel( URL mediaURL, Player mediaPlayer,String path,String port,String port1,String port2,String port3,String port4)
    {
         setLayout( new BorderLayout() ); // use a BorderLayout
        // Use lightweight components for Swing compatibility
         Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );

        try
        {
             // create a player to play the media specified in the URL
             mediaPlayer = Manager.createRealizedPlayer( mediaURL );

             // get the components for the video and the playback controls
             Component video = mediaPlayer.getVisualComponent();
             Component controls = mediaPlayer.getControlPanelComponent();

             if ( video != null )
                add( video, BorderLayout.CENTER ); // add video component

             if ( controls != null )
                add( controls, BorderLayout.SOUTH ); // add controls

             mediaPlayer.start(); // start playing the media clip
             ////// Transmit////////
            
             AVTransmit2.StartTransmint(path,Frm_IP.S_IP,port);
             //////////////////////////


              ////Truyền TCP //////
//             TCPServer a=new TCPServer(Frm_IP.S_IP,port1,port2,port3,port4);
//             System.out.println(Frm_IP.S_IP);
             ////////////////////////

          } // end try
          catch ( NoPlayerException noPlayerException )
          {
             System.err.println( "No media player found" );
          } // end catch
          catch ( CannotRealizeException cannotRealizeException )
          {
             System.err.println( "Could not realize media player" );
          } // end catch
          catch ( IOException iOException )
          {
             System.err.println( "Error reading from the source" );
          } // end catch
       } // end MediaPanel constructor
}
